package com.tf.six.controller;

// NotificationController.java



import com.tf.six.entity.Notification;
import com.tf.six.service.NotificationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notification")
@Tag(name = "通知管理", description = "处理系统通知相关操作")
public class NotificationController {

    @Autowired
    private NotificationService notificationService;

    @GetMapping("/user/{userId}")
    @Operation(summary = "获取用户通知")
    public List<Notification> getUserNotifications(
            @Parameter(description = "用户ID")
            @PathVariable Long userId) {
        return notificationService.lambdaQuery()
                .eq(Notification::getUserId, userId)
                .list();
    }

    @PutMapping("/read/{id}")
    @Operation(summary = "标记通知已读")
    public boolean markAsRead(@PathVariable Long id) {
        Notification notification = notificationService.getById(id);
        notification.setStatus(1);
        return notificationService.updateById(notification);
    }

    @PostMapping
    @Operation(summary = "发送系统通知")
    public boolean sendNotification(@RequestBody Notification notification) {
        return notificationService.save(notification);
    }
}